// Main.cc
#include "TcpServer.hpp"  // 负责处理IO
#include "Calculator.hpp" // 负责处理业务

Calculator calculator;

// for debug
void DefaultOnMessage(std::shared_ptr<Connection> connection)
{
    std::cout << "上层得到了数据：" << connection->Inbuffer() << std::endl;
    // 对报文进行处理
    std::string response_str = calculator.Handler(connection->Inbuffer());
    if (response_str.empty())
        return;
    lg(Debug, "%s", response_str.c_str());

    // 把response_str发送出去
    // 1.添加到发送缓冲区
    connection->AppendOutBuffer(response_str);
    // 2.调用写方法
    // connection->_send_cb(connection);
    connection->_tcp_server_ptr->Sender(connection);
}

int main()
{
    std::unique_ptr<TcpServer> epoll_svr(new TcpServer(8080, DefaultOnMessage));
    epoll_svr->Init();
    epoll_svr->Loop();
    return 0;
}